$($('head')[0]).append('<link rel="icon" href="/favico.ico" type="image/x-icon">');

/**
 * 进行设置商品的主图
 * @param title
 * @param id
 */
function set_main_image(title, id) {
    $.ajax({
        type: "GET",
        url: '/admin/setGoodImage',
        data: {gid: id, number: title},
        dataType: "json",
        success: function (data) {
            console.log(data.code)
            if (data.code == 0) {
                location.reload()
            }
        }
    })
}

/**
 * 进行显示该商品的封面信息
 * @param id
 * @param url
 */
function showimage(id, url) {
    $.ajax({
        type: "GET",
        url: '/admin/getGoodsCoverimage',
        data: {gid: id},
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                console.log(data.data)
                tab = data.data;
                for (let i = 0; i < tab.length; i++) {
                    tab[i].content = "<div><img style='width: 400px;height: 270px" +
                        "'   src='" + tab[i].content + "'><div style='width: 400px;" +
                        " text-align:center;margin-top: 10px;cursor:pointer;color: red'" +
                        " onclick='set_main_image(" + '"' + tab[i].title + '"' + "," + id + ")'>设置为封面主页</div></div>";
                }
                layer.tab({
                    area: ['500px', '400px'],
                    tab: tab
                });
            }
            console.log(data)
        }
    })
}

/**
 * 进行对商品进行审核通过
 * @param gid
 */
function checkGood(gid, goodsstate) {
    if (goodsstate == 2 || goodsstate == 4) {
        var failReason = 0;
        var integralReason = 0;
        var fail_content = '';
    } else {
        var failReason = $("input[name='failReason']:checked").val();
        var integralReason = $("input[name='integralReason']:checked").val();
        var fail_content = $("textarea[name='reason']").val();
    }
    //询问框
    if (goodsstate == 2) {
        layer.confirm('确定要审核通过吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "GET",
                url: '/admin/checkGood',
                data: {
                    gid: gid,
                    failReason: failReason,
                    integralReason: integralReason,
                    goodsstate: goodsstate,
                    fail_content: fail_content
                },
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        if (goodsstate == 2) {
                            location.reload();
                        }
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
        }, function () {

        });
    } else {
        $.ajax({
            type: "GET",
            url: '/admin/checkGood',
            data: {
                gid: gid,
                failReason: failReason,
                integralReason: integralReason,
                goodsstate: goodsstate,
                fail_content: fail_content
            },
            dataType: "json",
            success: function (data) {
                if (data.code == 0) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    if (goodsstate == 2) {
                        location.reload();
                    }
                } else {
                    layer.msg(data.msg);
                }
            }
        })
    }
}

/**
 * 下架
 *@param gid
 */
function LowerCheckGood(gid, goodsstate) {
    if (goodsstate == 2 || goodsstate == 4) {
        var failReason = 0;
        var integralReason = 0;
        var fail_content = '';
    } else {
        var failReason = $("input[name='failReason']:checked").val();
        var integralReason = $("input[name='integralReason']:checked").val();
        var fail_content = $("textarea[name='reason']").val();
    }
    $.ajax({
        type: "GET",
        url: '/admin/checkGood',
        data: {
            gid: gid,
            failReason: failReason,
            integralReason: integralReason,
            goodsstate: goodsstate,
            fail_content: fail_content
        },
        dataType: "json",
        success: function (data) {
            console.log(data.code)
            if (data.code == 0) {
                location.reload();
            } else {
                layer.msg(data.msg);
            }
        }
    })
}

/**
 * 展示商品关闭的原因
 * @param gid
 */
function showCloseReason(gid) {
    layer.open({
        type: 2,
        area: ['700px', '520px'],
        fixed: false, //不固定
        maxmin: true,
        content: '/admin/showReason?gid=' + gid,
        success: function (layero) {
            console.log('成功')
        },
        end: function (layero) {
            console.log('关闭')
            location.reload();
        }
    });
}

/**
 * 关闭弹框
 */
function closelay() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

/**
 * 处理当前错误
 */
function error_correction(id) {
    layer.confirm('确定该商品已纠错？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        console.log('确定')
        $.ajax({
            type: "GET",
            url: '/admin/error_correction',
            data: {
                id: id,
            },
            dataType: "json",
            success: function (data) {
                console.log(data.code)
                if (data.code == 0) {
                    location.reload();
                } else {
                    layer.msg(data.msg);
                }
            }
        })
    }, function () {
        console.log('取消')
    });
}
/**
 * 删除该错误日志记录
 */

function del_error_goods(id) {
    layer.confirm('确定要删除该记录？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        console.log('确定')
        $.ajax({
            type: "GET",
            url: '/admin/del_error_goods',
            data: {
                id: id,
            },
            dataType: "json",
            success: function (data) {
                console.log(data.code)
                if (data.code == 0) {
                    location.reload();
                } else {
                    layer.msg(data.msg);
                }
            }
        })
    }, function () {
        console.log('取消')
    });
}


